
use axum::{middleware, routing::{get, post}, Router};
use framework::{middleware::auth, state::AppState};
use monitor::operlog::middleware::OperLogLayer;
use std::sync::Arc;

use crate::ai_agent_plat::router as ai_agent_plat_router;
use crate::ai_agent::router as ai_agent_router;

pub fn api_router(state: Arc<AppState>) -> Router {
    let protected_router = Router::new()
        .merge(ai_agent_plat_router::router())
        .merge(ai_agent_router::router());

    let protected_api = Router::new()
        .merge(protected_router)
        .layer(OperLogLayer) // 这是外层，后于 auth 执行
        .layer(middleware::from_fn_with_state(state.clone(), auth)); // 这是内层，先于 OperLogLayer 执行

    Router::new()
        .merge(protected_api)
        .with_state(state)
}